package com.bt.lms.ui.page.sys.major;

import com.bt.lms.entity.Major;
import com.bt.lms.entity.page.Page;
import com.bt.lms.main.BotLmsApp;
import com.bt.lms.ui.page.common.PageLocation;
import com.bt.lms.ui.page.sys.utils.MyButton;
import com.bt.lms.ui.page.sys.utils.MyHBox;
import com.bt.lms.ui.page.sys.utils.MyVBox;
import com.bt.lms.ui.page.sys.utils.NetWorkUtils;
import com.bt.lms.ui.vo.PageSkipInfo;
import javafx.collections.ObservableList;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

/**
 * 专业详情界面
 */
public class PageDetails extends VBox {

    /**
     * 界面跳转信息
     */
    private final PageSkipInfo pageSkipInfo;

    /**
     * 要查看详情的专业编号
     */
    private final Major major;

    /**
     * 构建界面
     *
     * @param major        专业信息
     * @param pageSkipInfo 界面跳转信息
     */
    public PageDetails(Major major, PageSkipInfo pageSkipInfo) {

        //维护
        this.major = major;
        this.pageSkipInfo = pageSkipInfo;

        //大小
        this.setPrefWidth(BotLmsApp.PER_WIGHT);
        this.setPrefHeight(BotLmsApp.HEIGHT);

        //布局
        Insets insets = new Insets(0);
        this.setPadding(insets);

        //组件
        //定位区域
        String name = major.getName();
        PageLocation pageLocation = new PageLocation("系统管理", "学科/专业详情", name + "专业详情");
        this.getChildren().add(pageLocation);

        //详情区域
        MyVBox inputVBox = new MyVBox();
        inputVBoxInit(inputVBox);
        ObservableList<Node> inputChildren = this.getChildren();
        inputChildren.add(inputVBox);

        //控制区域
        MyHBox controlHBox = new MyHBox();
        controlHBoxInit(controlHBox);
        ObservableList<Node> controlChildren = this.getChildren();
        controlChildren.add(controlHBox);

    }


    /**
     * 输入区域初始化
     *
     * @param inputVBox 输入区域
     */
    private void inputVBoxInit(MyVBox inputVBox) {

        //布局
        Insets insets = new Insets(12);
        inputVBox.setPadding(insets);
        inputVBox.setSpacing(8);
        inputVBox.setAlignment(Pos.CENTER_LEFT);

        //组件（位置）
        String name = major.getName();
        Label locationLab = new Label(name + "专业详情");
        //组件添加
        ObservableList<Node> locationChildren = inputVBox.getChildren();
        locationChildren.add(locationLab);

        //组件（输入网格
        GridPane gridPane = inputGrid();
        inputVBox.getChildren().add(gridPane);
    }

    /**
     * 网格布局
     *
     * @return 网格布局
     */
    private GridPane inputGrid() {

        //新建网格布局
        GridPane res = new GridPane();

        //大小
        res.setPrefWidth(1280);
        res.setPadding(new Insets(5));
        res.setHgap(15);//间隙（左右）
        res.setVgap(15);//间隙（上下）

        //专业名称 name
        Label nameLab = new Label("学科/专业名称：");
        Label nameData = new Label(major.getName());
        res.add(nameLab, 0, 1);
        res.add(nameData, 1, 1);
        GridPane.setHalignment(nameLab, HPos.RIGHT);

        //专业编码 coding
        Label codingLab = new Label("学科/专业编码：");
        Label codingData = new Label(major.getCode());
        res.add(codingLab, 0, 2);
        res.add(codingData, 1, 2);
        GridPane.setHalignment(codingLab, HPos.RIGHT);

        //专业说明 status
        Label detailsLab = new Label("学科/专业详述：");
        Label detailsData = new Label(major.getDetails());

        res.add(detailsLab, 0, 3);
        res.add(detailsData, 1, 3);
        GridPane.setHalignment(detailsLab, HPos.RIGHT);

        return res;
    }

    /**
     * 控制区域初始化
     *
     * @param controlHBox 控制区域
     */
    private void controlHBoxInit(MyHBox controlHBox) {

        //布局
        Insets insets = new Insets(10);
        controlHBox.setPadding(insets);
        controlHBox.setSpacing(10);
        controlHBox.setAlignment(Pos.CENTER);

        //组件(取消)
        MyButton cancelBtn = new MyButton("取消");
        //大小控制
        Insets cancelBtnInsets = new Insets(10, 20, 10, 20);
        cancelBtn.setPadding(cancelBtnInsets);
        //组件添加
        controlHBox.getChildren().add(cancelBtn);
        //事件
        cancelBtn.setOnAction(event -> NetWorkUtils.reqMajorPagingPage(pageSkipInfo,new Page<>()));
    }
}
